/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.chl.mq._03_exchange;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.util.Date;

/**
 *
 * @author 陈宏亮
 */
public class EmitLog {

    private final static String EXCHANGE_NAME = "ex_log";

    public static void main(String[] args) throws Exception {
        //创建连接和频道  
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.2.221");
        factory.setUsername("guest");
        factory.setPassword("guest");
        try (Connection connection = factory.newConnection()) {
            Channel channel = connection.createChannel();
            // 声明转发器和类型  
            channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

            String message = new Date().toLocaleString() + " 今天天气很好耶，记个日志先";
            // 往转发器上发送消息  
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());

            System.out.println(" 发送日志：'" + message + "'");

            channel.close();
        }

    }
}
